package com.qf.demo03.contorller;

import com.qf.demo03.service.UserService;
import com.qf.demo03.vo.ResultVo;
import com.qf.demo03.vo.UserRegistVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class LoginController {

    @PostMapping("/regist")
    public ResultVo regist(UserRegistVo userRegistVo, HttpSession session) throws Exception {

        //0. 打日志


        //1. 校验验证码是否正确
        final String sessionCaptcha = (String) session.getAttribute("captcha");

        if (sessionCaptcha == null){
            return ResultVo.error("服务器出故障了，请刷新页面重试");
        }

        if (!sessionCaptcha.equals(userRegistVo.getCaptchar())){
            return ResultVo.error("验证码错误");
        }



        //3. 如果userService.registUser方法运行时没有抛出异常，则代表注册成功了，返回响应的json

        return ResultVo.ok();

    }


}
